package controller.back.nogenerate;

import java.util.HashMap;
import java.util.Map;

import model.generate.SvnProject;
import model.vo.MessageResult;
import model.vo.PageResult;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.back.SvnProjectBackService;
import utils.JsonUtils;
import controller.BaseController;
@Controller
@Scope("prototype")
@RequestMapping("/SvnMngrController")
public class SvnMngrController extends BaseController {
	SvnProjectBackService svnProjectService = new SvnProjectBackService();
	//返回页面
	@RequestMapping("/page.do")
	public String page(){
			return "back/svnMngr.jsp";
	}
	//查询项目
	@RequestMapping("/search.do")
	@ResponseBody
	public void search(String params, Integer pageNum, Integer pageSize){
		Map<String,Object> paramMap=new HashMap<String, Object>();
		if(params!=null&&!params.equals(""))
		{
			paramMap = JsonUtils.parseJson2Map(params, Object.class);
		}
		
		PageResult<SvnProject> pageResult = svnProjectService.findCollectionByConditionWithPage(paramMap, pageNum, pageSize);
		writeJsonToPage(pageResult);
	}
	//添加或修改
		@RequestMapping("/save.do")
		@ResponseBody
		public void save(SvnProject svnproject) throws Exception{
			if(svnproject.getId()==null){
				svnProjectService.save(svnproject);
			}else{
				svnProjectService.update(svnproject);
			}
			MessageResult result = new MessageResult(true,"操作成功");
			writeJsonToPage(result);
		}
		
		//删除
		@RequestMapping("/delete.do")
		@ResponseBody
		public void delete(String ids) throws Exception{
			String[] idArr = ids.split(",");
			Integer[] idArr2 = new Integer[idArr.length];
			for(int i=0;i<idArr.length;i++){
				idArr2[i] = new Integer(idArr[i]);
			}
			svnProjectService.deleteByIDs(idArr2);
			MessageResult result = new MessageResult(true,"操作成功");
			writeJsonToPage(result);
		}
}
